home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / H145.ZIP / ASXXXX_3.ZIP / LKLIST.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  4KB  |  228 lines

  1. /* lklist.c */
  2.  
  3. /*
  4.  * (C) Copyright 1989,1990
  5.  * All Rights Reserved
  6.  *
  7.  * Alan R. Baldwin
  8.  * 721 Berkeley St.
  9.  * Kent, Ohio  44240
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <alloc.h>
  15. #include "aslink.h"
  16.  
  17. /*
  18.  * Increment the count of lines on the
  19.  * page. If the page overflows put out a page
  20.  * skip and linker header.
  21.  */
  22. VOID
  23. slew(fp)
  24. FILE *fp;
  25. {
  26.     register i;
  27.  
  28.     if (lop++ >= NLPP) {
  29.         newpag(fp);
  30.         if (xflag == 0) {
  31.             fprintf(fp, "Hexidecimal\n\n");
  32.         } else
  33.         if (xflag == 1) {
  34.             fprintf(fp, "Octal\n\n");
  35.         } else
  36.         if (xflag == 2) {
  37.             fprintf(fp, "Decimal\n\n");
  38.         }
  39.         fprintf(fp, "Area       Addr   Size");
  40.         fprintf(fp, "   Decimal Bytes (Attributes)\n");
  41.         for(i=0;i<4;++i)
  42.             fprintf(fp, "      Value--Global");
  43.         fprintf(fp, "\n\n");
  44.         lop += 6;
  45.     }
  46. }
  47.  
  48. /*
  49.  * New Page
  50.  */
  51. VOID
  52. newpag(fp)
  53. FILE *fp;
  54. {
  55.     fprintf(fp, "\fASxxxx Linker %s,  page %u.\n", VERSION, ++page);
  56.     lop = 1;
  57. }
  58.  
  59. /*
  60.  * Area Map Output
  61.  */
  62. VOID
  63. lstarea(rp)
  64. struct area *rp;
  65. {
  66.     register struct area *op;
  67.     register struct areax *oxp;
  68.     register c, i, j;
  69.     register char *ptr;
  70.     int nmsym;
  71.     addr_t a0, ai, aj;
  72.     struct sym *sp;
  73.     struct sym **p;
  74.  
  75.     putc('\n', mfp);
  76.     slew(mfp);
  77.     /*
  78.      * Output Area Header
  79.      */
  80.     ptr = &rp->a_id[0];
  81.     while (ptr < &rp->a_id[NCPS]) {
  82.         if ((c = *ptr++) != 0) {
  83.             putc(c, mfp);
  84.         } else {
  85.             putc(' ', mfp);
  86.         }
  87.     }
  88.     ai = rp->a_addr;
  89.     aj = rp->a_size;
  90.     if (xflag == 0) {
  91.         fprintf(mfp, "   %04X   %04X", ai, aj);
  92.     } else
  93.     if (xflag == 1) {
  94.         fprintf(mfp, " %06o %06o", ai, aj);
  95.     } else
  96.     if (xflag == 2) {
  97.         fprintf(mfp, "  %05u  %05u", ai, aj);
  98.     }
  99.     fprintf(mfp, " = %6u. bytes ", aj);
  100.     if (rp->a_flag & A_ABS) {
  101.         fprintf(mfp, "(ABS");
  102.     } else {
  103.         fprintf(mfp, "(REL");
  104.     }
  105.     if (rp->a_flag & A_OVR) {
  106.         fprintf(mfp, ",OVR");
  107.     } else {
  108.         fprintf(mfp, ",CON");
  109.     }
  110.     if (rp->a_flag & A_PAG) {
  111.         fprintf(mfp, ",PAG");
  112.     }
  113.     fprintf(mfp, ")");
  114.     if (rp->a_flag & A_PAG) {
  115.         ai = (ai & 0xFF);
  116.         aj = (aj > 256);
  117.         if (ai || aj) { fprintf(mfp, "  "); }
  118.         if (ai)      { fprintf(mfp, " Boundary"); }
  119.         if (ai & aj)  { fprintf(mfp, " /"); }
  120.         if (aj)      { fprintf(mfp, " Length"); }
  121.         if (ai || aj) { fprintf(mfp, " Error"); }
  122.     }
  123.  
  124.     /*
  125.      * Find number of symbols in area
  126.      */
  127.     nmsym = 0;
  128.     oxp = rp->a_axp;
  129.     while (oxp) {
  130.         for (i=0; i<NHASH; i++) {
  131.             sp = symhash[i];
  132.             while (sp != NULL) {
  133.                 if (oxp == sp->s_axp)
  134.                     ++nmsym;
  135.                 sp = sp->s_sp;
  136.             }
  137.         }
  138.         oxp = oxp->a_axp;
  139.     }
  140.     if (nmsym == 0) {
  141.         putc('\n', mfp);
  142.         slew(mfp);
  143.         return;
  144.     }
  145.  
  146.     /*
  147.      * Allocate space for an array of pointers to symbols
  148.      * and load array.
  149.      */
  150.     if ( (p = (struct sym **) malloc(nmsym*sizeof(struct sym *)))
  151.         == NULL) {
  152.         fprintf(mfp, "\nInsufficient space to build Map Segment.\n");
  153.         slew(mfp);
  154.         return;
  155.     }
  156.     nmsym = 0;
  157.     oxp = rp->a_axp;
  158.     while (oxp) {
  159.         for (i=0; i<NHASH; i++) {
  160.             sp = symhash[i];
  161.             while (sp != NULL) {
  162.                 if (oxp == sp->s_axp) {
  163.                     p[nmsym++] = sp;
  164.                 }
  165.                 sp = sp->s_sp;
  166.             }
  167.         }
  168.         oxp = oxp->a_axp;
  169.     }
  170.  
  171.     /*
  172.      * Bubble Sort of Addresses in Symbol Table Array
  173.      */
  174.     j = 1;
  175.     while (j) {
  176.         j = 0;
  177.         sp = p[0];
  178.         a0 = sp->s_addr + sp->s_axp->a_addr;
  179.         for (i=1; i<nmsym; ++i) {
  180.             sp = p[i];
  181.             ai = sp->s_addr + sp->s_axp->a_addr;
  182.             if (a0 > ai) {
  183.                 j = 1;
  184.                 p[i] = p[i-1];
  185.                 p[i-1] = sp;
  186.             }
  187.             a0 = ai;
  188.         }
  189.     }
  190.  
  191.     /*
  192.      * Symbol Table Output
  193.      */
  194.     i = 0;
  195.     while (i < nmsym) {
  196.         if (i % 4 == 0) {
  197.             fprintf(mfp, "\n");
  198.             slew(mfp);
  199.             fprintf(mfp, "     ");
  200.         }
  201.         sp = p[i];
  202.         aj = sp->s_addr + sp->s_axp->a_addr;
  203.         if (xflag == 0) {
  204.             fprintf(mfp, "  %04X  ", aj);
  205.         } else
  206.         if (xflag == 1) {
  207.             fprintf(mfp, "%06o  ", aj);
  208.         } else
  209.         if (xflag == 2) {
  210.             fprintf(mfp, " %05u  ", aj);
  211.         }
  212.         ptr = &sp->s_id[0];
  213.         while (ptr < &sp->s_id[NCPS]) {
  214.             if ((c = *ptr++) != 0) {
  215.                 putc(c, mfp);
  216.             } else {
  217.                 putc(' ', mfp);
  218.             }
  219.         }
  220.         if (++i < nmsym)
  221.             if (i % 4 != 0)
  222.                 fprintf(mfp, " | ");
  223.     }
  224.     putc('\n', mfp);
  225.     free(p);
  226.     slew(mfp);
  227. }
  228.